using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using System.Collections.Generic;

namespace Pay.Service.AutoMapper {
	public class ChargeMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public ChargeMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		public void Create() {
			_cfg.CreateMap<charge_dto, Charge>()
				.ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
				.ForMember(dest => dest.OrderNo, src => src.MapFrom(c => c.order_no))
				.ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
				.ForMember(dest => dest.BindId, src => src.MapFrom(c => c.bind_id))
				.ForMember(dest => dest.Profit, src => src.MapFrom(c => c.profit.ToJson()))
				.ForMember(dest => dest.Status, src => src.MapFrom(c => c.status))
				.ForMember(dest => dest.PayId, src => src.MapFrom(c => c.pay_id))
				.ForMember(dest => dest.OrderAmount, src => src.MapFrom(c => c.order_amount))
				.ForMember(dest => dest.SubsidyAmount, src => src.MapFrom(c => c.subsidy_amount))
				.ForMember(dest => dest.PayAmount, src => src.MapFrom(c => c.pay_amount))
				.ForMember(dest => dest.FeeAmount, src => src.MapFrom(c => c.fee_amount))
				.ForMember(dest => dest.Amount, src => src.MapFrom(c => c.amount))
				.ForMember(dest => dest.CardType, src => src.MapFrom(c => c.card_type))
				.ForMember(dest => dest.ProtocolNo, src => src.MapFrom(c => c.protocol_no))
				.ForMember(dest => dest.AccountName, src => src.MapFrom(c => c.account_name))
				.ForMember(dest => dest.IdCard, src => src.MapFrom(c => c.id_card))
				.ForMember(dest => dest.BankCode, src => src.MapFrom(c => c.bank_code))
				.ForMember(dest => dest.BankName, src => src.MapFrom(c => c.bank_name))
				.ForMember(dest => dest.AccountNo, src => src.MapFrom(c => c.account_no))
				.ForMember(dest => dest.FrontNotify, src => src.MapFrom(c => c.front_notify))
				.ForMember(dest => dest.Mobile, src => src.MapFrom(c => c.mobile))
				.ForMember(dest => dest.Vaild, src => src.MapFrom(c => c.vaild))
				.ForMember(dest => dest.Merchant, src => src.Ignore())
				.ForMember(dest => dest.IsOut, src => src.MapFrom(c => c.is_out))
				.ForMember(dest => dest.RcvMobile, src => src.MapFrom(c => c.rcv_mobile))
				.ForMember(dest => dest.RcvIdCard, src => src.MapFrom(c => c.rcv_id_card))
				.ForMember(dest => dest.RcvBankCode, src => src.MapFrom(c => c.rcv_bank_code))
				.ForMember(dest => dest.RcvBankName, src => src.MapFrom(c => c.rcv_bank_name))
				.ForMember(dest => dest.RcvAccountNo, src => src.MapFrom(c => c.rcv_account_no))
				.ForMember(dest => dest.RcvAccountName, src => src.MapFrom(c => c.rcv_account_name))
				.ForMember(dest => dest.SettleFee, src => src.MapFrom(c => c.settle_fee))
				.ForMember(dest => dest.MerchantFee, src => src.MapFrom(c => c.merchant_fee))
				.ForMember(dest => dest.MerchantSettle, src => src.MapFrom(c => c.merchant_settle))
				.ForMember(dest => dest.PlatFee, src => src.MapFrom(c => c.plat_fee))
				.ForMember(dest => dest.PlatSettle, src => src.MapFrom(c => c.plat_settle))
				.ForMember(dest => dest.Binder, src => src.Ignore());
			_cfg.CreateMap<Charge, charge_dto>()
				.ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
				.ForMember(dest => dest.order_no, src => src.MapFrom(c => c.OrderNo))
				.ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
				.ForMember(dest => dest.bind_id, src => src.MapFrom(c => c.BindId))
				.ForMember(dest => dest.profit, src => src.MapFrom(c => c.Profit.ToObject<List<bind_merchant_item>>()))
				.ForMember(dest => dest.order_time, src => src.MapFrom(c => c.OrderTime.ToDateTime()))
				.ForMember(dest => dest.status, src => src.MapFrom(c => c.Status))
				.ForMember(dest => dest.pay_id, src => src.MapFrom(c => c.PayId))
				.ForMember(dest => dest.order_amount, src => src.MapFrom(c => c.OrderAmount))
				.ForMember(dest => dest.subsidy_amount, src => src.MapFrom(c => c.SubsidyAmount))
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => c.PayAmount))
				.ForMember(dest => dest.fee_amount, src => src.MapFrom(c => c.FeeAmount))
				.ForMember(dest => dest.amount, src => src.MapFrom(c => c.Amount))
				.ForMember(dest => dest.protocol_no, src => src.MapFrom(c => c.ProtocolNo))
				.ForMember(dest => dest.card_type, src => src.MapFrom(c => c.CardType))
				.ForMember(dest => dest.account_name, src => src.MapFrom(c => c.AccountName))
				.ForMember(dest => dest.front_notify, src => src.MapFrom(c => c.FrontNotify))
				.ForMember(dest => dest.id_card, src => src.MapFrom(c => c.IdCard))
				.ForMember(dest => dest.bank_code, src => src.MapFrom(c => c.BankCode))
				.ForMember(dest => dest.bank_name, src => src.MapFrom(c => c.BankName))
				.ForMember(dest => dest.account_no, src => src.MapFrom(c => c.AccountNo))
				.ForMember(dest => dest.mobile, src => src.MapFrom(c => c.Mobile))
				.ForMember(dest => dest.vaild, src => src.MapFrom(c => c.Vaild))
				.ForMember(dest => dest.is_out, src => src.MapFrom(c => c.IsOut))
				.ForMember(dest => dest.rcv_mobile, src => src.MapFrom(c => c.RcvMobile))
				.ForMember(dest => dest.rcv_id_card, src => src.MapFrom(c => c.RcvIdCard))
				.ForMember(dest => dest.rcv_bank_code, src => src.MapFrom(c => c.RcvBankCode))
				.ForMember(dest => dest.rcv_bank_name, src => src.MapFrom(c => c.RcvBankName))
				.ForMember(dest => dest.rcv_account_no, src => src.MapFrom(c => c.RcvAccountNo))
				.ForMember(dest => dest.rcv_account_name, src => src.MapFrom(c => c.RcvAccountName))
				.ForMember(dest => dest.settle_fee, src => src.MapFrom(c => c.SettleFee))
				.ForMember(dest => dest.merchant_fee, src => src.MapFrom(c => c.MerchantFee))
				.ForMember(dest => dest.merchant_settle, src => src.MapFrom(c => c.MerchantSettle))
				.ForMember(dest => dest.plat_fee, src => src.MapFrom(c => c.PlatFee))
				.ForMember(dest => dest.plat_settle, src => src.MapFrom(c => c.PlatSettle))
				.ForMember(dest => dest.pay_info, src => src.MapFrom(c => c.PayInfo))
				.ForMember(dest => dest.merchant, src => src.MapFrom(c => c.Merchant))
				.ForMember(dest => dest.binder, src => src.MapFrom(c => c.Binder))
				.ForMember(dest => dest.merchant_no, src => src.MapFrom(c => c.Merchant.MerchantNo));

			_cfg.CreateMap<native_model, charge_dto>()
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => decimal.Parse(c.tran_amount) / 100M))
				.ForMember(dest => dest.settle_fee, src => src.MapFrom(c => c.settle_fee / 100M))
				.ForMember(dest => dest.profit, src => src.MapFrom(c => c.binds))
				.ForMember(dest => dest.pay_info, src => src.MapFrom(c => new pay_info_dto {
					pay_channel = c.pay_channel,
					order_no = c.order_no,
					pay_no = c.order_no,
					pay_code = c.pay_code,
					pay_type = c.pay_type,
					settle_type = c.settle_type,
					transaction_no = c.transaction_no
				}));

			_cfg.CreateMap<quick_pay_model, charge_dto>()
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => decimal.Parse(c.tran_amount) / 100M))
				.ForMember(dest => dest.settle_fee, src => src.MapFrom(c => c.settle_fee / 100M))
				.ForMember(dest => dest.profit, src => src.MapFrom(c => c.binds))
				.ForMember(dest => dest.merchant_no, src => src.MapFrom(c => c.merchant_no))
				.ForMember(dest => dest.pay_info, src => src.MapFrom(c => new pay_info_dto {
					pay_channel = c.pay_channel,
					order_no = c.order_no,
					pay_no = c.order_no,
					pay_code = c.pay_code,
					pay_type = c.pay_type,
					settle_type = c.settle_type
				}));

			_cfg.CreateMap<mall_model, charge_dto>()
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => decimal.Parse(c.tran_amount) / 100M))
				.ForMember(dest => dest.pay_info, src => src.MapFrom(c => new pay_info_dto {
					pay_channel = c.pay_channel,
					order_no = c.order_no,
					pay_no = c.order_no,
					pay_code = c.pay_code,
					pay_type = c.pay_type,
					settle_type = c.settle_type,
					transaction_no = c.transaction_no
				}));

			_cfg.CreateMap<gateway_pay_model, charge_dto>()
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => decimal.Parse(c.tran_amount) / 100M))
				.ForMember(dest => dest.profit, src => src.MapFrom(c => c.binds))
				.ForMember(dest => dest.pay_info, src => src.MapFrom(c => new pay_info_dto {
					pay_channel = c.pay_channel,
					order_no = c.order_no,
					pay_no = c.order_no,
					pay_code = c.pay_code,
					pay_type = c.pay_type,
					settle_type = c.settle_type,
					transaction_no = c.transaction_no
				}));

			_cfg.CreateMap<apply_receive, charge_dto>()
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => decimal.Parse(c.tran_amount) / 100M))
				.ForMember(dest => dest.profit, src => src.MapFrom(c => c.binds))
				.ForMember(dest => dest.pay_info, src => src.MapFrom(c => new pay_info_dto {
					pay_channel = c.pay_channel,
					order_no = c.order_no,
					pay_no = c.order_no,
					pay_code = c.pay_code,
					pay_type = c.pay_type,
					settle_type = c.settle_type
				}));
		}
	}
}